<template>
    <div class="item">
        <input type="checkbox" name="" id="" v-model="item.iscomplete" @click="changeState()">
        <span class="mark">{{item.title}}</span>
        <button @click="deletetodoByid()">删除</button>
    </div>
</template>

<script lang="ts" setup>
import { toRefs } from 'vue'
import { change_state, deleteByid } from '../request/api'
import $bus from '../utils/bus'
interface todo {
    id: string,
    title: string,
    iscomplete: boolean,
}


const props = defineProps<{
    item:todo
}>()
const changeState = async ()=>{
    let res = await change_state(item.value.id)
    $bus.emit('getState')
}
const deletetodoByid = async ()=>{
    let res = await deleteByid(item.value.id)
    console.log(res);
    $bus.emit('fetchtodoList')
    $bus.emit('getState')
}
let { item } = toRefs(props)

</script>

<style scoped>
.item {
    width: 80%;
    background-color: #2f305e;
    border-radius: 15px;
    height: 30px;
    margin: 10px 0;
    padding: 0 10px;
    display: flex;
    align-items: center;
    position: relative;
}
.item button {
    display: none;
    position: absolute;
    right: 10px;
    background-color: #ff7b85;
    border: none;
    outline: none;
    padding:  1px 10px;
    color: white;
    font-weight: 800;
    font-size: 14px;
}
.item:hover > button{
    display: block;
}
.item span {
    color: #e3e3e3;
    max-width: 70%;
    width: 80%;
    padding-left: 10px;
}


</style>